<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp" %>
<!DOCTYPE html>
<html>
<head>
<title>预约规则列表</title>
 <%@ include file="/WEB-INF/component/commonCSS.jsp" %>
<!--[if lt IE 9]>
        <script src="lib/js/html5shiv.min.js"></script>
        <script src="lib/js/respond.min.js"></script>
    <![endif]-->
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
	<section class="content-header">
		<h1>预约记录列表</h1>
		<ol class="breadcrumb">
			<li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i>首页</a></li>
			<li class="active">药品招标管理</li>
            <li class="active">预约管理</li>
			<li class="active">预约</li>
			<li class="active">预约记录列表</li>
		</ol>
	</section>

	<section class="content">
		<div class=" box box-success">
			<div class="box-body">
				<div class=" form-inline">
					<div class="form-group form-group-xs">
						<label for="txtDrugName">预约日期：</label> 
						 <input style="width: 100px;" placeholder="预约日期" name="subscribeDate" id="subscribeDate" type="text"  value="" readonly="readonly" data-provide="datepicker" data-date-fmt="yyyy-MM-dd" placeholder="yyyy-mm-dd">
					</div>
						<button type="button" onclick="likeQuery();" class="btn btn-success btn-sm">查&nbsp;询</button>
				   </div>
			</div>
		</div>
		<table class="jqgrid" id="gridlist"></table>
		<div id="gridpage"></div>
		
		 <div class="box-footer text-center">
                    <button type="button" onclick="back();" class="btn btn-default btn-sm">返&nbsp;&nbsp;回</button>
         </div>
		<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header bg-primary">
						<button type="button" class="close" data-dismiss="modal" aria-label="Close">
							<span aria-hidden="true">&times;</span>
						</button>
						<h5 class="modal-title" id="exampleModalLabel">预约新增</h5>
					</div>
					<div class="modal-body">
						<form>
							<input type="hidden" id="bidSubscribeRecordId" name="bidSubscribeRecordId" value="">
							<input type="hidden" id="bidSubscribeDetailId" name="bidSubscribeDetailId" value="">
							<input type="hidden" id="bidSubscribeId" name="bidSubscribeId" value="">
							<input type="hidden" id="projId" name="projId" value="">
							<div class="form-group form-group-xs">
								<input type="hidden" name="operflag" id="operflag" value="" /> 
								<label for="recipient-name" class=" control-label">项目名称：</label>
								<div class="" id="projName">
								</div>
							</div>
							<div class="form-group form-group-xs">
								<label for="recipient-name" class=" control-label">预约日期：</label>
								<div style="width: 160px;">
										<select id="detailId" class="form-control">
										</select>
									</div>
							</div>
							<div class="form-group form-group-xs">
								<label for="recipient-name" class=" control-label">预约时间：</label>
								<div style="width: 160px;">
										<select id="detailIdTime" class="form-control">
										</select>
								</div>
							</div>
						</form>
					</div>
					<div class="modal-footer">
						<button type="button" onclick="save();" class="btn btn-primary btn-sm">保存</button>
						<button type="button" id="closebt" class="btn btn-danger btn-sm" data-dismiss="modal">关闭</button>
					</div>
				</div>
			</div>
		</div>
		<form action="${ctx }/bidSubscribe/toSubscribeEditJsp.html" method="post" id="FormSubmit">
			<input type="hidden" id="bidSubscribeId" name="bidSubscribeId">
		</form>
		<form action="${ctx}/bidSubscribeRecord/toSuccessJsp.html" method="post" id="FormSuccess">
			<input type="hidden" id="bidSubscribeIdSuc" name="bidSubscribeId">
			<input type="hidden" id="subscribeDateSuc" name="subscribeDate">
			<input type="hidden" id="subscribeStarttime" name="subscribeStarttime">
			<input type="hidden" id="subscribeEndtime" name="subscribeEndtime">
			<input type="hidden" id="projNameSuc" name="projName">
		</form>
	</section>
   <%@ include file="/WEB-INF/component/commonJS.jsp" %>
    <script src="${ctx}/lib/plugins/daterangepicker/moment.js"></script>
    <script src="${ctx}/lib/plugins/daterangepicker/daterangepicker.js"></script>
	<script type="text/javascript">
		$(function() {
			$("#projId").HNSelect({
	            url: "${pageContext.request.contextPath}/selectController/getDicBidCompany.html", data: { ID: '' }, defaultText: "<option value=''>请选择</option>",
	        });
			$("#gridlist").jqGrid({
								url : "getRecordData.html",
								mtype : "POST",
								datatype : "json",
								autowidth : true,
								height : 270,
								colNames : ['预约记录id','预约详情id','预约设置id', '项目名称', '预约日期','预约时间','现场确认地址','操作'],
								colModel : [
											{name : 'bidSubscribeRecordId',width : 100,align : "center",hidden : true,sortable : false},
								            {name : 'bidSubscribeDetailId',width : 100,align : "center",hidden : true,sortable : false},
								            {name : 'bidSubscribeId',width : 100,align : "center",hidden : true,sortable : false},
								            {name : 'projName',width : 140,align : "left",sortable : false},
										    {name : 'subscribeDateStr',width : 160,align : "center",sortable : false},
										    {name : 'subTime',width : 160,align : "center",sortable : false,
										    	formatter : function(val, opts,
														rowdata) {
													return rowdata.subscribeStarttimeStr+" - "+rowdata.subscribeEndtimeStr;
											}	
										    },
										    {name : 'address',width : 120,align : "center",sortable : false,
												formatter : function(val, opts,
														rowdata) {
													return "<a href=\"javascript:lookJsp('"+rowdata.subscribeDateStr+"','"+rowdata.bidSubscribeId+"','"+rowdata.projName+"','"+rowdata.subscribeStarttimeStr+"','"+rowdata.subscribeEndtimeStr+"');\">查看</a>";
												}
										    },
										    {name : 'oper',width : 120,align : "center",sortable : false,
												formatter : function(val, opts,
														rowdata) {
													return "<a href=\"javascript:edit('"+rowdata.bidSubscribeRecordId+"','"+rowdata.subscribeDateStr+"','"+rowdata.bidSubscribeId+"','"+rowdata.projName+"','"+rowdata.subscribeStarttimeStr+"','"+rowdata.subscribeEndtimeStr+"');\">修改</a>";
												}
										    }
										
										],
								rowNum : 20,
								rowList : [ 10, 20, 50,100 ],
								rownumbers : true,
								pager : "#gridpage",
								multiselect : true,
								viewrecords : true,
								caption : "预约记录列表",
								jsonReader : {
									repeatitems : false,
									id : "ids"
								}
							});
			$("#gridlist").jqGrid('navGrid', '#gridpage', {
				add : false,
				edit : false,
				del : false,
				search : false,
				refresh : false
			});

			 $(window).trigger("resize");
		});
		
		function save(){
		var bidSubscribeRecordId = $("#bidSubscribeRecordId").val();
		var bidSubscribeId = $("#bidSubscribeId").val();
		var subscribeDate =  $("#detailId").val();
		var arr = new Array();
		var timeStr = $("#detailIdTime").val();
		arr = timeStr.split(" - ");
	 	var subscribeStarttime = arr[0];
	   	var subscribeEndtime  =  arr[1];
			$.ajax({
                url: "${pageContext.request.contextPath}/bidSubscribeRecord/updateRecord.html",//action地址
                data: { 
                	"bidSubscribeRecordId": bidSubscribeRecordId,
                	"bidSubscribeId":bidSubscribeId,
                	"subscribeDate":subscribeDate,
                	"subscribeStarttime":subscribeStarttime,
                	"subscribeEndtime":subscribeEndtime
                },//传值
                type: "post",//执行方式get or post 默认以post方式执行
                dataType:"json",
                success: function (result) {//执行成功后 提示
                	
                   if (result.success){
                	   $.HN.message.alert('保存成功！', '信息', 'success');
                	   likeQuery();
                	   $("#closebt").click();
                	   return;
                   } 
                },
                error: function () {// 如果执行出现错误 提示
                	$.HN.message.alert('保存失败！', '信息', 'error');
                }
            });
		}
		function lookJsp(id,projName,startTime,endTime){
			$("#bidSubscribeIdSuc").val(id);
			$("#subscribeDateSuc").val(dateStr);
			$("#subscribeStarttime").val(startTime);
			$("#subscribeEndtime").val(endTime);
			$("#projNameSuc").val(projName);
			$("#FormSuccess").submit();
		}
		function likeQuery() {
			var subscribeDate = $("#subscribeDate").val();
			$("#gridlist").jqGrid('setGridParam',{
				       	    	datatype:'json',
				                postData:{
				                	"subscribeDate":subscribeDate
				                	},
				                page : 1
			}).trigger("reloadGrid");
		}
		
		
		function edit(recordId,dateStr,subscribeId,name,startTime,endTime){
			
			$("#detailId").HNSelect({
			    url: "${pageContext.request.contextPath}/selectController/getBidSubscribeDetailDate.html", data: { subscribeId : subscribeId },defaultselect:dateStr, defaultText: "<option value=''>请选择</option>",
			  });
			$("#detailIdTime").HNSelect({
			    url: "${pageContext.request.contextPath}/selectController/getBidSubscribeDetailTime.html", data: { bidSubscribeId: subscribeId },defaultselect:startTime+" - "+endTime, defaultText: "<option value=''>请选择</option>",
			  });
			
		       $('.modal-title').html('预约编辑');
		               $('#exampleModal').modal({
		                      keyboard: true
		                  });
		      $("#bidSubscribeRecordId").val(recordId);
		   	  $("#bidSubscribeId").val(subscribeId);
		      $("#projName").html(name);
		}
		  
		function back(){
	    	window.location.href="${ctx}/bidSubscribe/toProduceSubscribeJsp.html";
	    }
	</script>
</body>
</html>